package com.lihao.jetpackcore.ext

import android.app.Activity
import android.view.View
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment

/**
 * 作者　: hegaojian
 * 时间　: 2020/5/2
 * 描述　:
 */
fun Fragment.nav(): NavController {
    return NavHostFragment.findNavController(this)
}

fun nav(view: View): NavController {
    return Navigation.findNavController(view)
}

/**
 * 在Activity中调用,viewId指NavHostFragment的id
 * 底层是调用的 Navigation.findNavController(activity, viewId)函数
 */
fun Activity.nav(viewId: Int): NavController {
    return findNavController(viewId)
}

